﻿
@{
    ViewBag.Title = "OfficialAccountMenu";
    Layout = "~/Views/Shared/layoutCommon.cshtml";
}

<section class="content-header">
    <h1>
        菜单管理
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>主页</a></li>
        <li class="active">菜单管理</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-header">
                    <button class="btnadd btn btn-success btn-sm" id="addbtn" type="button">添加菜单</button>
                    <button class="btnadd btn btn-success btn-sm" id="sendbtn" type="button">推送菜单</button>
                </div>
                <div class="box-body table-responsive no-padding">
                    <table class="table table-bordered table-hover" id="tblist">
                        <colgroup>
                            <col style="width: 300px" />
                            <col style="width: 270px" />
                        </colgroup>
                        <tbody id="tbodylist"></tbody>
                    </table>
                    <div class="no-data" id="nodata" style="display:none;">
                        <div class="img-box"></div>
                        <div class="text">暂无数据</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
@section scriptsBottom{
    <script src="@Url.Content("~/lib/art-template/template-web.js")"></script>
    <script id="dataItemTpl" type="text/html">
        {{each data}}
        <tr>
            <th><i class="bookmark"></i>{{$value.MenuName}}</th>
            <td>
                <button type="button" class="btn btn-success btn-xs" onclick="BMCW.showTopLayer('添加子菜单','@Url.Action("MenuEdit", "Wx")?pid={{$value.MenuID}}', 550, 600)">添加子菜单</button>
                <button type="button" class="btn btn-info btn-xs" onclick="BMCW.showTopLayer('修改菜单','@Url.Action("MenuEdit", "Wx")?id={{$value.MenuID}}', 550, 600)">修改菜单</button>
                <button type="button" class="btn btn-danger btn-xs" onclick="del({{$value.MenuID}})">删除</button>
            </td>
        </tr>
        {{include 'childTemplate' $value}} <!--引入子模板-->
        {{/each}}
    </script>
    <script id="childTemplate" type="text/html">
        {{each ChildMenu}}
        <tr>
            <td><i class="bookmark three"></i>{{$value.MenuName}}</td>
            <td>
                <button type="button" class="btn btn-info btn-xs" onclick="BMCW.showTopLayer('修改菜单','@Url.Action("MenuEdit", "Wx")?id={{$value.MenuID}}', 550, 600)">修改菜单</button>
                <button type="button" class="btn btn-danger btn-xs" onclick="del({{$value.MenuID}})">删除</button>
            </td>
        </tr>
        {{/each}}
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#addbtn").click(function () {
                var url = '@Url.Action("MenuEdit", "Wx")';
                BMCW.showTopLayer('添加菜单', url, 550, 600);
            });

            $("#sendbtn").click(function () {
                var url = '@Url.Action("SendToWxCreateMenu", "Wx")';
                BMCW.DataConfirm("确认要执行此操作吗?", function () {
                    BMCW.loading("处理中");
                    BMCW.ajax({
                        url: url,
                        type: 'GET',
                        dataType: "json",
                        success: function (data) {
                            BMCW.closeAll();
                            if (data.status == 0) {
                                BMCW.alert("已生成微信菜单");
                            } else {
                                BMCW.alert(data.message);
                            }
                        }
                    });
                })
            })
            initData();
        });

        //查询
        function initData() {
            var url = '@Url.Action("GetMenuList", "Wx")'
            //查询列表
            BMCW.ajax({
                url: url,
                type: 'GET',
                dataType: "json",
                success: function (data) {
                    if (data.data.length < 1) {
                        $("#nodata").show();
                        document.getElementById('tbodylist').innerHTML = "";
                        return;
                    }
                    $("#nodata").hide();
                    //模板渲染
                    var html = template('dataItemTpl', data);
                    document.getElementById('tbodylist').innerHTML = html;
                }
            });
        }

        //删除
        function del(id) {
            var url = '@Url.Action("DelMenu", "Wx")'
            BMCW.DataConfirm("", function () {
                BMCW.ajax({
                    url: url,
                    type: "POST",
                    data: {
                        mid: id
                    },
                    success: function (o) {
                        if (o.status == 0) {
                            BMCW.msg("删除成功", function () {
                                initData();
                            });

                        } else {
                            BMCW.alert("删除失败");
                        }
                    }
                });
            })
        }
    </script>
}

